import time
import requests

def request_authcode_url():
    """
    请求二维码接口
    :return: response.header
    """

    res_authcode_json =requests.get('http://192.168.3.36:8000/api/v0/web/authcode')

    return res_authcode_json.headers

def request_login_url(username,password,authCode=None):
    """
    请求login接口
    :param username: 用户名
    :param password: 密码
    :param authCode: 验证码
    :return: 返回登录response
    """

    res_authCode_json = request_authcode_url()

    uuid =res_authCode_json["uuid"]

    temp_authCode =res_authCode_json["Randcode"] if authCode is None else authCode

    login_form_data = {
        "uuid":uuid,
        "authCode":temp_authCode,
        "username":username,
        "password":password
    }

    time.sleep(1)

    res_login_json = requests.post("http://192.168.3.36:8000/api/v0/web/login",json=login_form_data)

    print(res_login_json.text)

    time.sleep(1)
    return res_login_json